
/**
 * 添加用户
 */
function toAddUser() {
	var w = $.ligerDialog.open({
				title : '新增供应链用户',
				url : 'toAddUser.do',
				height : 350,
				width : 500,
				isResize : false,
				isDrag : false
			});
	w.show();
}

/**
 * 修改用户
 * 
 * @param rowindex
 */
function toModifyUser(rowindex) {
	var uid = grid.getData()[rowindex].id;
	var w = $.ligerDialog.open({
				title : '修改供应链用户',
				url : 'toModifyUser.do?id=' + uid,
				height : 350,
				width : 500,
				isResize : false,
				isDrag : false
			});
	w.show();
}

/**
 * 修改密码
 * 
 * @param rowindex
 */
function toModifyPassword(rowindex) {
	var uid = grid.getData()[rowindex].id;
	var w = $.ligerDialog.open({
				title : '修改供应链用户密码',
				url : 'toModifyPassword.do?id=' + uid,
				height : 350,
				width : 500,
				isResize : false,
				isDrag : false
			});
	w.show();
}

function toAllocateRole(rowindex) {
	var uid = grid.getData()[rowindex].id;
	var uNature = grid.getData()[rowindex].userNature;
	var w = $.ligerDialog.open({
				title : '分配角色',
				url : '../../../manager/system/user/toAllocateRole.do?id='
						+ uid + '&userNature=' + uNature,
				height : 650,
				width : 750,
				isResize : false,
				isDrag : false
			});
	w.show();
}

/**
 * 锁定用户
 * 
 * @param rowindex
 */
function lockUser(rowindex) {
	$.ligerDialog.confirm('确定锁定', function(yes) {
				if (yes) {
					var uid = grid.getData()[rowindex].id;
					$.post("lockUser.do?id=" + uid, function(data) {
								if (data == "success") {
									alert("锁定成功");
									window.location.reload();
								} else {
									alert("锁定失败");
									window.location.reload();
								}
							});
				}
			});
}

/**
 * 解锁用户
 * 
 * @param rowindex
 */
function unlockUser(rowindex) {
	$.ligerDialog.confirm('确定解锁', function(yes) {
				if (yes) {
					var uid = grid.getData()[rowindex].id;
					$.post("unlockUser.do?id=" + uid, function(data) {
								if (data == "success") {
									alert("解锁成功");
									window.location.reload();
								} else {
									alert("解锁失败");
									window.location.reload();
								}
							});
				}
			});
}

/**
 * 删除用户
 * 
 * @param rowindex
 */
function deleteUser(rowindex) {
	$.ligerDialog.confirm('确定删除', function(yes) {
				if (yes) {
					var uid = grid.getData()[rowindex].id;
					$.post("deleteUser.do?id=" + uid, function(data) {
								if (data == "success") {
									window.parent.f_tip('删除成功');
				    				reload_cur_tab();
								} else {
									window.parent.f_tip('删除失败');
				    				reload_cur_tab();
								}
							});
				}
			});
}

/**
 * 角色分配相关JS
 */
$(function() {
			// 移到右边
			$('#add').click(function() {
						$('#select1 option:selected').remove()
								.appendTo('#select2');
					});
			// 移到左边
			$('#remove').click(function() {
						$('#select2 option:selected').remove()
								.appendTo('#select1');
					});
			// 双击选项
			$('#select1').dblclick(function() {
						$("option:selected", this).remove()
								.appendTo('#select2');
					});
			// 双击选项
			$('#select2').dblclick(function() {
						$("option:selected", this).remove()
								.appendTo('#select1');
					});
			// 左边向上按钮
			$('#left_up').click(function() {
				var index = $('#select1 option')
						.index($('#select1 option:selected:first'));
				var $recent = $('#select1 option:eq(' + (index - 1) + ')');
				if (index > 0) {
					var $options = $('#select1 option:selected').remove();
					setTimeout(function() {
								$recent.before($options);
							}, 10);
				}
			});
			// 左边向下按钮
			$('#left_down').click(function() {
				var index = $('#select1 option')
						.index($('#select1 option:selected:last'));
				var len = $('#select1 option').length - 1;
				var $recent = $('#select1 option:eq(' + (index + 1) + ')');
				if (index < len) {
					var $options = $('#select1 option:selected').remove();
					setTimeout(function() {
								$recent.after($options);
							}, 10);
				}
			});
			// 右边向上按钮
			$('#right_up').click(function() {
				var index = $('#select2 option')
						.index($('#select2 option:selected:first'));
				var $recent = $('#select2 option:eq(' + (index - 1) + ')');
				if (index > 0) {
					var $options = $('#select2 option:selected').remove();
					setTimeout(function() {
								$recent.before($options);
							}, 10);
				}
			});
			// 右边向下按钮
			$('#right_down').click(function() {
				var index = $('#select2 option')
						.index($('#select2 option:selected:last'));
				var len = $('#select2 option').length - 1;
				var $recent = $('#select2 option:eq(' + (index + 1) + ')');
				if (index < len) {
					var $options = $('#select2 option:selected').remove();
					setTimeout(function() {
								$recent.after($options);
							}, 10);
				}
			});
		});

function allocateRole() {
	var roleIds = [];
	var s = $('#select1 option');
	for (var i = 0; i < s.length; i++) {
		if (typeof(s[i]) != 'function') {
			roleIds[i] = s[i].value;
		}
	}
	$('#select1').val(roleIds);
	var options = {
		type : 'POST',
		success : function(data) {
			if (data == "success") {
				var succ = $.ligerDialog.success("分配角色成功", function(yes) {
					if (yes) {
						parent.window.location.reload();
					}
				});
				$(succ.dialog.winbtns).remove();
			} else {
				$.ligerDialog.error("分配角色失败");
			}
		}
	}, $allocateRoleForm = $("#allocateRoleForm");
	$allocateRoleForm.ajaxSubmit(options);
	return false;
}

function cancelAllocateRole() {
	parent.window.location.reload();
}